import React from 'react'
import PropTypes from 'prop-types'
import Component, { mapStateToProps, mapDispatchToProps } from '@components/Component'
import { connect } from 'react-redux'
import { Modal, Form, Checkbox } from 'antd'
import style from './Index.module.less'
const { Item } = Form
class FileCreator extends Component {
  formRef = React.createRef()

  onSubmit (d) {
    this.props.onChange(d)
    this.props.hide()
  }

  cancelHandle () {
    this.props.hide()
  }

  render () {
    return (
      <Modal
        title='生成文书'
        width={800}
        open={this.props.visible}
        destroyOnClose
        maskClosable={false}
        onOk={() => this.formRef.current.submit()}
        onCancel={() => this.cancelHandle()}
      >
        <Form name='file-creator' ref={this.formRef} onFinish={d => this.onSubmit(d)}>
          <Item name='files' label='文书' rules={[{ required: true, message: '请选择要生成的文书' }]}>
            <Checkbox.Group className={style.checkbox} options={this.props.fileList.map(li => ({ label: li, value: li }))} />
          </Item>
        </Form>
      </Modal>
    )
  }
}

const mapState = mapStateToProps(function (state) {
  return {
    userInfo: state.basic.userInfo
  }
})

const mapDispatch = mapDispatchToProps(function (dispatch) {
  return {

  }
})

export default connect(mapState, mapDispatch)(FileCreator)

FileCreator.proptypes = {
  visible: PropTypes.bool,
  hide: PropTypes.func,
  fileList: PropTypes.array,
  bizid: PropTypes.string,
  onChange: PropTypes.func
}

FileCreator.defaultProps = {
  visible: false,
  hide: () => {},
  fileList: [],
  bizid: '',
  onChange: () => {}
}
